﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCDto.Common.Area;
using BCService.Common.Area;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace BCTMSRESTful.Controllers.Anonymous
{
    [Route("api/v1/[controller]")]
    [ApiController]
    public class AreaController : BCTMSRESTfulAPIController
    {
        private readonly IProvinceService provinceService;
        private readonly ICityService cityService;
        private readonly ICountyService countyService;

        public AreaController(IProvinceService provinceService, ICityService cityService, ICountyService countyService)
        {
            this.provinceService = provinceService;
            this.cityService = cityService;
            this.countyService = countyService;
        }

        /// <summary>
        /// 获取以城市首字母分组的城市列表
        /// </summary>
        /// <response code="200">以城市首字母分组的城市列表。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<CityDto>), 200)]
        public IActionResult CitiesInitialsGroup()
        {
            return Ok(cityService.GetCitiesInitialsGroup());
        }

        /// <summary>
        /// 获取热门城市列表
        /// </summary>
        /// <response code="200">以城市首字母分组的城市列表。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<CityDto>), 200)]
        public IActionResult HotCities()
        {
            return Ok(cityService.GetHotCities());
        }

        /// <summary>
        /// 获取省市列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(IEnumerable<ProvinceCityDto>), 200)]
        public IActionResult Get()
        {
            return Ok(provinceService.GetAllProvinces());
        }

        /// <summary>
        /// 获取区县列表
        /// </summary>
        /// <param name="cityId">城市Id</param>
        /// <returns></returns>
        [HttpGet("City/{city_id}/[action]")]
        [ProducesResponseType(typeof(IEnumerable<CountyViewDto>), 200)]
        public IActionResult County([FromRoute(Name ="city_id")]long cityId)
        {
            return Ok(countyService.Query(cityId));
        }
    }
}
